<?php
require_once (APPLICATION_DIR."/library/external/XOAD/xoad.php");

class AdmissionController extends DRX_Controller 
{
	function xoadGetMeta()
	{
		//register function can be called by JS
		XOAD_Client::mapMethods($this,array("loadPartner","loadPageContent","downloadForm"));
	}    
    
	function prepareLeftPane($left_active = 0)
    {
        $smarty 	= DRX::load("smarty");
        $partner    = new Partner();
        $partnerInfo	= $partner->getAllPartner();
        $partner_list   = $partnerInfo->fetchList();
		$smarty->assign("partner_list",$partner_list);
		
		$has_left_menu	= true;
		$smarty->assign("has_left_menu",$has_left_menu);        
		$smarty->assign("left_active",$left_active);
		
		$leftmenu 	= $smarty->fetch("admission/leftpane.tpl");
		$smarty->assign("leftmenu",$leftmenu);
    }
    
    function preparePathWeb($left_active)
    {
    }
    
    function prepareLayout($left_active = 0)
    {
        $topmenu = new Topmenu();
        $topmenu->prepareTopMenu();
        
        $topmenu= new Topmenu();
        $topmenu->prepareTopBanner(ADMISSION_ID);
        
//        $this->preparePathWeb($left_active);
        $this->prepareLeftPane($left_active);
    }
        
    function partnerAction()
    {
        global $arrArgs;
        $partner_id = $arrArgs[0];
        $programme = new Programme();
        $admissionInfo = $programme->getAllAdmissionOfPartner($partner_id);
        $i = 0;
        $admissionList = array();
        
        while ($admissionInfo->fetch())
        {
            $admissionList[$i]['pro_id']        = $admissionInfo->pro_id;
            $admissionList[$i]['partner_id']    = $admissionInfo->partner_id;            
            $partner_title = $admissionInfo->partner_title;
            $admissionList[$i]['pro_menu_id']   = $admissionInfo->pro_menu_id;
            $admissionList[$i]['pro_title']     = $admissionInfo->pro_title;
            $admissionList[$i]['requirement']   = $admissionInfo->pro_requirement;
            $admissionList[$i]['procedure']     = $admissionInfo->pro_procedure;
            $admissionList[$i]['applyform']     = $this->get_admission_form_url($admissionInfo->pro_applyform);
            $i++;
        }
        $partner = new Partner();
        $partnerInfo = $partner->getPartnerByID($partner_id);
        if ($partnerInfo->fetch())
        {
            $partner_intro = $partnerInfo->partner_intro;
        }        
        $smarty 	= DRX::load("smarty");
        $this->prepareLayout($partner_id);
        $smarty->assign("partner_intro",$partner_intro);
        $smarty->assign("number_of_program",count($admissionList));
        $script = $smarty->fetch("admission/admission.js");
        $smarty->assign("module_script",$script);
        $smarty->assign("admissionList",$admissionList);
        $smarty->assign("content_title","Admission - " . $partner_title);
        $content = $smarty->fetch("admission/admission.tpl");
        $smarty->assign("content",$content);
        $smarty->display("solvay.tpl");
    }
    
	function indexAction()
	{
		$smarty 	= DRX::load("smarty");
		
		$this->prepareLayout();
		$node		= new Node();
		$node->preparePage(ADMISSION_ID);
		$smarty->assign("content_title","Admission");
		$smarty->display("solvay.tpl");
	}
	
	function get_admission_form_url($file_location)
	{
	    if ($file_location)
	    {
    	    $list = explode("/",$file_location);
    	    $filedir  = $list[count($list)-2];
    	    $filename = $list[count($list)-1];
    	    $url = ADMISSION_FORM_URL . $filename;
	    }
	    return $url;
	}   
}
?>